<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-06 00:34:26
 * @LastEditTime : 2019-12-25 17:02:52
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <style type="text/css">
        .van-cell__value {
            text-align: right;
        }

        .user-img {
            width: 50px;
            height: 50px;
            border-radius: 25px;
            overflow: hidden;
            display: inline-block;
        }

        .user-img img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" title="计划设置" left-arrow @click-left="onClickLeft">
            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <van-cell title="开始时间" :value="SDate" @click="openDate(1)">
                    </van-cell>
                    <van-cell title="结束时间" :value="EDate" @click="openDate(2)">
                    </van-cell>

                    <div class="btn-padding">
                        <van-button type="primary" block style="border-radius: 0;" @click="dateConfirm">确定</van-button>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>

        <van-popup v-model="showDate" round position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" :min-date="minDate" @confirm="confirmDate"
                @cancel="cancelDate" cancel-button-text="清空" />
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        // $('.init-full').show();

        var branchData = api.pageParam.branchData;

        var dateIndex = 0;
        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                showDate: false,
                currentDate: new Date(),
                minDate: new Date(),
                SDate: '',
                EDate: '',
                BHID: 0
            },
            created: function () {
                var that = this;

            },
            methods: {
                dateConfirm() {
                    var that = this;

                    var obj = {
                        S_Type: 1,
                        S_NBranchID: branchData.id,
                        S_SDate: that.SDate,
                        S_EDate: that.EDate,
                        S_BHID: 0,
                        S_ClientID: 0,
                        S_BHDeID: 0
                    }
                    FLD.ajax('APP_BHJHADDN', obj, function (res) {
                        if (res.ds[0].status == 200) {
                            that.BHID = res.ds[0].BHID;
                            api.sendEvent({
                                name: 'refreshTripList'
                            });
                            
                            layer.open({
                                content: '计划添加成功',
                                skin: 'msg',
                                time: 2,
                                end: function () {
                                    api.closeWin();
                                }
                            });

                        } else {
                            layer.open({
                                content: res.ds[0].msg,
                                skin: 'msg',
                                time: 2
                            });
                        }
                    })




                },
                openDate(index) {
                    dateIndex = index;
                    this.currentDate = new Date()
                    this.showDate = true;
                },
                confirmDate(value) {
                    if (dateIndex == 1) {
                        this.SDate = FLD.getFormatDate(value).split(' ')[0]
                    } else {
                        this.EDate = FLD.getFormatDate(value).split(' ')[0]
                    }
                    this.showDate = false;
                },
                cancelDate(value) {
                    if (dateIndex == 1) {
                        this.SDate = ''
                    } else {
                        this.EDate = '';
                    }
                    this.showDate = false;
                },
                onClickLeft() {
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>